# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=reportlab

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.0
pkgrel=2
pkgdesc="A proven industry-strength PDF generating solution (mingw-w64)"
arch=('any')
license=('custom')
url="http://www.reportlab.org/rl_toolkit.html"
depends=("${MINGW_PACKAGE_PREFIX}-freetype")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
    "${MINGW_PACKAGE_PREFIX}-python3")
source=(http://www.reportlab.com/ftp/${_realname}-${pkgver}.tar.gz)
md5sums=('a4fd40abcfb604aa3bd907181133c071')
 
prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cd "${srcdir}"
  cp -r ${_realname}-${pkgver} build-python2
  cp -r ${_realname}-${pkgver} build-python3
}

build() {
  export FT_LIB=${MINGW_PREFIX}/lib/libfreetype.a
  export FT_INC=${MINGW_PREFIX}/include/freetype2
  # Build python 2 module
  cd "${srcdir}"/build-python2
  ${MINGW_PREFIX}/bin/python2 setup.py build

  # Build python 3 module
  cd "${srcdir}"/build-python3
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python2-reportlab() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/build-python2"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/python2-${_realname}/LICENSE
}

package_python3-reportlab() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/build-python3"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-reportlab() {
  package_python2-reportlab
}

package_mingw-w64-i686-python3-reportlab() {
  package_python3-reportlab
}

package_mingw-w64-x86_64-python2-reportlab() {
  package_python2-reportlab
}

package_mingw-w64-x86_64-python3-reportlab() {
  package_python3-reportlab
}
